import { PayloadUser } from '@libs/common/decorator';
import { IndexInterceptor } from '@libs/common/interceptors';
import { Body, Controller, Post, UseInterceptors } from '@nestjs/common';

import { DepartmentConfigService } from './department-config.service';
import {
  IndexDepartmentConfigDto,
  ShowDepartmentConfigDto,
  SwitchDepartmentConfigDto,
  UpdateDepartmentConfigDto,
} from './dto/department-config.dto';

@Controller('ding/department/config')
export class DepartmentConfigController {
  constructor(
    private readonly departmentConfigService: DepartmentConfigService,
  ) {}

  @Post('index')
  @UseInterceptors(new IndexInterceptor())
  index(@Body() dto: IndexDepartmentConfigDto) {
    return this.departmentConfigService.index(dto);
  }

  @Post('show')
  show(@Body() dto: ShowDepartmentConfigDto) {
    return this.departmentConfigService.show(dto);
  }

  @Post('update')
  update(
    @Body() dto: UpdateDepartmentConfigDto,
    @PayloadUser() user: SC.User.SysInfo,
  ) {
    return this.departmentConfigService.update(dto);
  }

  @Post('sync')
  sync() {
    return this.departmentConfigService.sync();
  }

  @Post('switch')
  switch(@Body() dto: SwitchDepartmentConfigDto) {
    return this.departmentConfigService.switch(dto);
  }
}
